//
//  MeatShopHeader.m
//  PigMarket
//
//  Created by 张敬 on 2019/8/15.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "MyMeatShopHeader.h"
#import "MeatTipLabel.h"



@interface MyMeatShopHeader()

@property (nonatomic, strong) UIImageView *bgIcon;

@property (nonatomic, strong) UIImageView *mContentView;

@property (nonatomic, strong) MeatTipLabel *tipLabel;

@property (nonatomic, strong) UIButton *goingSeparateBtn;


/**
 MeatShopHeader 's shopNameLab -> UIlabel
 */
@property (nonatomic, strong) UILabel *shopNameLab;



/**
 MeatShopHeader 's shopDetailLab -> UIlabel
 */
@property (nonatomic, strong) UILabel *shopDetailLab;



/**
 MeatShopHeader 's shopIcon -> UIImageView
 */
@property (nonatomic, strong) UIImageView *shopIcon;


/**
 MeatShopHeader 's messageBtn -> UIButton
 */
@property (nonatomic, strong) UIButton *messageBtn;



/**
 MeatShopHeader 's icons -> NSArray
 */
@property (nonatomic, strong) NSArray *icons;


/**
 MeatShopHeader 's titles -> NSArray
 */
@property (nonatomic, strong) NSArray *titles;


/**
 MeatShopHeader 's titleVaules -> NSArray
 */
@property (nonatomic, strong) NSArray *titleVaules;


@end


@implementation MyMeatShopHeader

- (void)setupUI
{
    [self addSubview:self.bgIcon];
    [self addSubview:self.mContentView];
    
    [self.mContentView addSubview:self.shopIcon];
    [self.mContentView addSubview:self.shopNameLab];
    [self.mContentView addSubview:self.shopDetailLab];
    [self.mContentView addSubview:self.messageBtn];
    
    [self addSubview:self.tipLabel];
    [self.tipLabel addSubview:self.goingSeparateBtn];

    [self addList];
    [self addTitleList];

}


- (void)addList{
    
    __block CGFloat gap = 40.f;
    @weakify(self);
    [self.icons enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        @strongify(self);
        
        UIImageView *icon = [UIImageView makeImageByImageName:obj cornerRadius:0];
        icon.size = CGSizeMake(40, 40 );
        icon.mj_y = TJ_StatusBarHeight ;
        icon.mj_x = KScreenWidth - self.icons.count *gap +gap*idx;
        icon.isNeedAnimation = YES;
        [self addSubview:icon];
        
        icon.tapBlock = ^{
            
        };
    }];
}


- (void)addTitleList{
    
    __block CGFloat gap = (KScreenWidth - 30) / 3.f;
    @weakify(self);
    [self.titleVaules enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        @strongify(self);
        UILabel *valueLab = [UILabel makeLabelWithText:obj textColor:UIColorFromRGB(0x424242) font:mFont(17) textAliment:1];
        valueLab.frame = CGRectMake(15 + gap *idx, 115, gap, 18);
        
        UILabel *titleLab = [UILabel makeLabelWithText:self.titles[idx] textColor:UIColorFromRGB(0x808080) font:mFont(12) textAliment:1];
        titleLab.frame = CGRectMake(15 +gap *idx, valueLab.bottom + 5, gap, 18);
        
        [self.mContentView addSubview:valueLab];
        [self.mContentView addSubview:titleLab];
        
        if (idx >0) {
            CAShapeLayer *line = [CAShapeLayer layer];
            line.fillColor = UIColorFromRGB(0xDFDFDF).CGColor;
            UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(15 + gap *(idx), 126 , 1, 30)];
            line.path = path.CGPath;
            [self.mContentView.layer addSublayer:line];
        }
    }];
    
}

- (void)setupLayout
{
    self.height = 330 + TJ_StatusBarHeight;
    
    {
        _bgIcon.size = CGSizeMake(KScreenWidth, TJ_StatusBarHeight + 177);
        _bgIcon.mj_x = _bgIcon.mj_y = 0;
    }
    
    {
        _mContentView.size = CGSizeMake(KScreenWidth, 200);
        _mContentView.mj_x = 0;
        _mContentView.mj_y = TJ_StatusBarHeight + 54;
    }
    
    {
        _tipLabel.mj_y = _mContentView.bottom + 17;
        _tipLabel.width = KScreenWidth - 30;
        _tipLabel.mj_x = 15;
    }
    
    {
        _goingSeparateBtn.size = CGSizeMake(60, 27);
        _goingSeparateBtn.mj_y = (_tipLabel.height - _goingSeparateBtn.height)/2.0;
        _goingSeparateBtn.mj_x = _tipLabel.width - _goingSeparateBtn.width - 15;
    }
    
    {
        _shopIcon.size = CGSizeMake(70, 70);
        _shopIcon.mj_x = 35;
        _shopIcon.mj_y = 20;
    }
    
    {
        _shopNameLab.mj_x = _shopIcon.right + 15;
        _shopNameLab.mj_y = 29;
        _shopNameLab.size = CGSizeMake(KScreenWidth - 155, 21);
    }
    
    
    {
        _shopDetailLab.size = CGSizeMake(_shopNameLab.width, 18);
        _shopDetailLab.mj_x = _shopNameLab.mj_x;
        _shopDetailLab.mj_y = _shopNameLab.bottom + 6;
    }
    
    
    {
        _messageBtn.mj_y = 18;
        _messageBtn.size = CGSizeMake(60, 18);
        _messageBtn.mj_x = self.mContentView.width - _messageBtn.width - 18;
        
    }
}

#pragma mark - lifecycle methods
#pragma mark - networking methods
#pragma mark - response methods
#pragma mark - public methods
#pragma mark - tableview.delegate methods
#pragma mark - tableview.datasource methods
#pragma mark - setter methods
#pragma mark - getter methods

- (UIImageView *)bgIcon{
    
    if (!_bgIcon) {
        _bgIcon = [UIImageView new];
        _bgIcon.image = [UIImage imageNamed:@"meat_adopt_bg"];
    }
    return _bgIcon;
}


- (UIImageView *)mContentView{
    
    if (!_mContentView) {
        _mContentView = [UIImageView new];
        _mContentView.image = [UIImage imageNamed:@"meat_separate_part"];
    }
    return _mContentView;
}


- (MeatTipLabel *)tipLabel{
    if (!_tipLabel) {
        _tipLabel = [[MeatTipLabel alloc] init];
        _tipLabel.height = 44;
        _tipLabel.backgroundColor = UIColorFromRGB(0xFFF3DE);

        
        NSString *contentStr = @"您有1头小仔猪，赶快去分割售卖吧~";
        NSMutableAttributedString *aims = [contentStr createAttributingByIcon:nil downIndexImage:nil textColor:UIColorFromRGB(0xDE6402) font:mFont(14)];
        _tipLabel.attributedText = aims;
    }
    return _tipLabel;
}

- (UIButton *)goingSeparateBtn{
    
    if (!_goingSeparateBtn) {
        _goingSeparateBtn = [UIButton makeButtonWithText:@"去分割" textColor:UIColorFromRGB(0xDE6402) font:mFont(12) textAliment:1 cornerRadius:13.5];
        _goingSeparateBtn.layer.borderColor = UIColorFromRGB(0xFFB22B).CGColor;
        _goingSeparateBtn.layer.borderWidth = 1;
        _goingSeparateBtn.backgroundColor = UIColorFromRGB(0xFFF3DE);
    }
    return _goingSeparateBtn;
}

- (UIImageView *)shopIcon{
    
    if (!_shopIcon) {
        _shopIcon = [[UIImageView alloc] init];
        _shopIcon.image = [UIImage imageNamed:@"meat_shop_Icon"];
        [self addShadowAndCircleCorner:_shopIcon.layer corner:35];
    }
    return _shopIcon;
}


- (UILabel *)shopNameLab{
    
    if (!_shopNameLab) {
        _shopNameLab = [UILabel makeLabelWithText:@"石头剪刀铺" textColor:UIColorFromRGB(0x333333) font:mFont(20) textAliment:0];
    }
    return _shopNameLab;
}


- (UILabel *)shopDetailLab{
    
    if (!_shopDetailLab) {
        _shopDetailLab = [UILabel makeLabelWithText:@"整猪转让，电话请联系18519283443" textColor:UIColorFromRGB(0x808080) font:mFont(13) textAliment:0];
    }
    return _shopDetailLab;
}





- (UIButton *)messageBtn{
    
    if (!_messageBtn) {
        _messageBtn = [UIButton makeButtonWithText:@"切换买家" textColor:KWhiteColor font:mFont(13) textAliment:1 cornerRadius:5];
        _messageBtn.backgroundColor = KClearColor;
        kWeakSelf(self);
        _messageBtn.tapBlock = ^{
        };
    }
    
    return _messageBtn;
}


- (NSArray *)icons{
    
    if (!_icons) {
        _icons = @[@"meat_buy_message", @"meat_shop_more"];
    }
    return _icons;
}


- (NSArray *)titles{
    
    if (!_titles) {
        _titles = @[@"近期访客", @"当月成交", @"当月收益"];
    }
    return _titles;
}


- (NSArray *)titleVaules{
    
    if (!_titleVaules) {
        _titleVaules = @[@"26", @"99", @"89"];
    }
    return _titleVaules;
}




@end
